import request from "./request.js";
// 商品分类管理

//   商品列表数据

async function getGoods(parems) {
    console.log(parems);
    let res = await request({
        url: 'goods',
        method: 'get',
        params: {
            query: parems.query,
            pagenum: parems.pagenum,
            pagesize: parems.pagesize
        }
    })
    return res
}

// 商品 分类 数据 

async function getcategories(parems) {
    let res = await request({
        url: 'categories',
        method: 'get',
        params: {
            type: parems.type,
            pagenum: parems.pagenum,
            pagesize: parems.pagesize
        }
    })
    return res
}
//添加 分类
async function getaddsrot(parems) {
    console.log(parems);
    let res = await request({
        url: 'categories',
        method: 'post',
        data: {
            cat_pid: parems.cat_pid,
            cat_name: parems.cat_name,
            cat_level: parems.cat_level
        }
    })
    return res
}




// 修改 分类 
async function setedit(parems) {
    let res = await request({
        url: `categories/${parems.id}`,
        method: 'put',
        data: {
            cat_name: parems.cat_name
        }
    })
    return res
}
// 删除 分类
async function deleteedit(id) {
    let res = await request({
        url: `categories/${id}`,
        method: 'delete',

    })
    return res
}

// 获取 动态 参数 数据

async function getdatalist(id) {
    let res = await request({
        url: `categories/${id}/attributes`,
        params: {
            sel: 'many'
        }
    })
    return res
}

//获取 动态 参数 数据 列表


async function adddatalist(parems) {
    console.log(parems);
    let res = await request({
        url: `categories/${parems.id}/attributes`,
        method: 'post',
        data: {
            attr_name: parems.attr_name,
            attr_sel: parems.attr_sel
        }
    })
    return res
}

// 编辑提交参数

async function Submitparameter(parems) {
    // console.log(parems);
    let res = await request({
        url: `categories/${parems.id}/attributes/${parems.attrId}`,
        method: 'put',
        data: {
            attr_name: parems.attr_name,
            attr_sel: parems.attr_sel,
            attr_vals: parems.attr_vals
        }
    })
    return res
}

//删除参数

async function deleteparameter(parems) {
    // console.log(parems);
    let res = await request({
        url: `categories/${parems.id}/attributes/${parems.attrId}`,
        method: 'delete',

    })
    return res
}

// 添加 tag 标签


async function puttag(parems) {
    console.log(parems);
    let res = await request({
        url: `categories/${parems.id}/attributes/${parems.attrId}`,
        method: 'put',
        data: {
            attr_name: parems.attr_name,
            attr_sel: parems.attr_sel,
            attr_vals: parems.attr_vals
        }

    })
    return res
}


//商品管理模块-商品分类
//商品分类列表
const catelist = async(msg) => {
        let data = await request.get('/categories', msg)
        return data
    }
    //填加分类
const addcate = async(msg) => {
        let data = await request.post('/categories', msg)
        return data
    }
    // 编辑提交分类
const editcate = async(msg) => {
        // let data = await server.put('/categories/' + msg.id, { cat_name: msg.name })
        let data = await request({ url: `/categories/${msg.id}`, date: { cat_name: msg.name }, method: 'put' })
        return data
    }
    //删除分类
const delcate = async(msg) => {
    let data = await request({ url: `/categories/${msg.id}`, method: 'delete' })
    return data
}

//分类参数功能
//参数列表
const attrlist = async(msg) => {
        let data = await request.get(`categories/${msg.id}/attributes`, { params: { sel: msg.sel } })
        return data
    }
    //填加参数或属性
const addattr = async(msg) => {
        let data = await request.post(`categories/${msg.id}/attributes`, {
            attr_name: msg.attr_name,
            attr_sel: msg.attr_sel
        })
        return data
    }
    //删除参数或属性

//根据id查询参数

//提交更新参数或属性
const updateattr = async(msg) => {
    let data = await request({ url: `categories/${msg.id}/attributes/${msg.attr_id}`, data: { attr_name: msg.attr_name, attr_sel: msg.attr_sel, attr_vals: msg.attr_vals }, method: 'put' })
    return data
}


export {
    getGoods,
    getcategories,
    setedit,
    deleteedit,
    getaddsrot,
    getdatalist,
    adddatalist,
    Submitparameter,
    deleteparameter,
    puttag,
    catelist,
    addcate,
    editcate,
    delcate,
    attrlist,
    addattr,
    updateattr
}